***Summary of Subject Disposition;

%macro prnt (program=, disname=, ds_list=, popfl=, tpop=, title=, num=, numm=); 
/*%let popfl=%str(armcd ne " ");*/
proc sort data=adam.adsl out=adsla(keep=subjid SAFFL enrlfl COMPLFL randafl randbfl PKFL PDFL armcd actarmcd trt01a trt02a trt03a trt04a trt05a trt06a status 
									REASEXCL randano randbno);
by subjid;
run; 

data adslaa;
set adsla;
length arma armb armcda armcdb $3. ;
arma=strip(substr(actarmcd,1,3));
if index(actarmcd,"/") then armb=strip(substr(actarmcd,5));
else armb=" ";
if length(arma)<3 then arma=" ";
if length(armb)<3 then armb=" ";
armcda=strip(substr(armcd,1,3));
armcdb=strip(substr(armcd,5));
*!!!!!!!!! Temporary set "Y";
/*if randafl="N" then randafl="Y"; else randafl=strip(randafl);*/
run;

*Create data for all parts to use in or=5 & 6;
proc sort data=adslaa out=_adslb;
by subjid;
run;

*Create data for separate part;
proc sort data=adslaa out=adslb;
by subjid;
where &popfl ;
run;


*Subjects Enrolled;

proc sql; 
/*create table enr as select count(subjid) as overall, "Subjects Enrolled [N]" as col0 length 100, 1 as or from adsla;*/
create table enr as select count(subjid) as overall, "Subjects Enrolled [N]" as col0 length 100, 1 as or from adslb;
quit;

*Subjects Randomized;

proc sql; 
create table rnd as 
select count(subjid) as nn, "A"||strip(armcda) as arm, "Part A" as part length 10, "Subjects Randomized [N]" as col0 length 100, 2 as or from adslb where randafl="Y" 
   and armcda ne " " group by armcda
outer union corr
select count(subjid) as nn, "B"||strip(armcdb) as arm, "Part B" as part length 10, "Subjects Randomized [N]" as col0 length 100, 2 as or from adslb where randbfl="Y" 
   and armcdb ne " " group by armcdb
;
quit;

proc sort data=rnd; by or col0 part; run;
proc transpose data=rnd out=rnd1(drop=_name_); by  or col0 ; id arm; var nn; run;

data rnd1;
set rnd1;
overall=sum(aabc,abca,acab);
run;


%macro outer(v,r,t,condit,conditi,def,p);
/*select count(trt0&v.a) as nn, "Subjects Who Received Study Product [n(%)]" as col0 length 100, "&p"||strip(arm&r) as arm, "Day &t" as visit length 12, &v as orda, 3 as or, */
/*   "&def" as colyn length 200 from adslb where trt0&v.a &condit and arm&r &conditi group by arm&r*/

select count(trt0&v.a) as nn, "Subjects Who Received Study Product [n(%)]" as col0 length 100, "&p"||strip(armcd&r) as arm, "Day &t" as visit length 12, &v as orda, 3 as or, 
   "&def" as colyn length 200 from adslb where trt0&v.a &condit and armcd&r &conditi group by armcd&r

%mend;

*for "Yes";

proc sql;
create table y1 as 
%outer(1,a,1,%str(ne " "),%str(ne " "),Yes,A) outer union corr %outer(2,a,2,%str(ne " "),%str(ne " "),Yes,A) outer union corr %outer(3,a,3,%str(ne " "),%str(ne " "),Yes,A) ;
create table y2 as 
%outer(4,b,4,%str(ne " "),%str(ne " "),Yes,B) outer union corr %outer(5,b,5,%str(ne " "),%str(ne " "),Yes,B) outer union corr %outer(6,b,6,%str(ne " "),%str(ne " "),Yes,B) ;
quit;

proc sort data=y1; by visit or orda col0 colyn; run;
proc transpose data=y1 out=y10(drop=_name_); by  visit or orda col0 colyn; id arm; var nn; run;

proc sort data=y2; by visit or orda col0 colyn; run;
proc transpose data=y2 out=y20(drop=_name_); by  visit or orda col0 colyn; id arm; var nn; run;

proc sql; create table y3 as select * from y10 outer union corr select * from y20 order by or, orda; quit; 

data y3;
length part $10.;
set y3;
if orda in (1 2 3) then part="Part A";
else part="Part B";
ordb=1;
run;

data adslb; set adslb; run; 

*To test for count ;
proc sort data=adslb out=arma; by arma; run;
proc sort data=adslb out=armb; by armb; run;

*For "No";
/*%macro skip;*/
proc sql; 
create table rndn as
select count(subjid) as nn, "A"||strip(armcda) as arm, "Part A" as part length 10, "Subjects Randomized [N]" as col0 length 100, 2 as or from adslb 
   where randafl="Y" and armcda ne " " group by armcda
outer union corr 
select count(subjid) as nn, "B"||strip(armcdb) as arm, "Part B" as part length 10, "Subjects Randomized [N]" as col0 length 100, 2 as or from adslb 
   where randbfl="Y" and armcdb ne " " group by armcdb;
quit;

proc sort data=rndn; by or col0 part ; run;
proc transpose data=rndn out=rndn1(drop=_name_); by  or col0 part ; id arm; var nn; run;

data nr(rename=(aabc=aabcn abca=abcan acab=acabn babc=babcn bbca=bbcan bcab=bcabn) drop=or col0);
set rndn1;
run;

proc sort data=y3 out=y3; by part; run;
proc sort data=nr out=nr; by part; run;

data n3;
merge y3 nr;
by part;
colyn="No";
if aabc ne . then aabc=aabcn-aabc; if abca ne . then abca=abcan-abca; if acab ne . then acab=acabn-acab;
if babc ne . then babc=babcn-babc; if bbca ne . then bbca=bbcan-bbca; if bcab ne . then bcab=bcabn-bcab;
ordb=2;
*!!!!!! Temporary set until data updated lock;
/*if abca<0 and abca ne . then do; abca=0; end;*/
drop aabcn abcan acabn babcn bbcan bcabn;
run;

*Subjects who Completed;
*** updated to show results per sequence ;
proc sql; 
create table cmpn as
select distinct count(subjid) as nn, "A"||strip(armcda) as arm, "Part A" as part length 10,
   "Subjects Who Completed Part A [n(%)]" as col0 length 100, 4.1 as or, 1 as ordb, "Yes" as colyn length 200
/*   from adslb where complfl="Y" and armcda ne " " group by armcda*/
      from adslb where arma ne " " and armcda ne " " group by armcda

outer union corr 
select distinct count(subjid) as nn, "A"||strip(armcda) as arm, "Part A" as part length 10, 
   "Subjects Who Completed Part A [n(%)]" as col0 length 100, 4.1 as or, 2 as ordb, "No" as colyn length 200
/*   from adslb where complfl="N" and armcda ne " " group by armcda*/
         from adslb where arma=" " and armcda ne " " group by armcda
outer union corr 
select distinct count(subjid) as nn, "B"||strip(armcdb) as arm, "Part B" as part length 10,
   "Subjects Who Completed Part B [n(%)]" as col0 length 100, 4.3 as or, 1 as ordb, "Yes" as colyn length 200
/*   from adslb where complfl="Y" and armcdb ne " " group by armcdb*/
      from adslb where armb ne " " and armcdb ne " " group by armcdb

outer union corr 
select distinct count(subjid) as nn, "B"||strip(armcdb) as arm, "Part B" as part length 10,
   "Subjects Who Completed Part B [n(%)]" as col0 length 100, 4.3 as or, 2 as ordb, "No" as colyn length 200
/*   from adslb where complfl="N" and armcdb ne " " group by armcdb;*/
      from adslb where armb=" " and armcdb ne " " group by armcdb;
quit;
data adslb; set adslb; run;

/*proc sort data=cmpn nodupkey out=cmpn; by _all_; run;*/

data aaa bbb;
set cmpn;
if part="Part A" then output aaa;
else output bbb;
run;

proc sort data=aaa; by or col0 part ordb colyn; run;
proc transpose data=aaa out=aaa1(drop=_name_); by  or col0 part ordb colyn; id arm; var nn; run;

proc sort data=bbb; by or col0 part ordb colyn; run;
proc transpose data=bbb out=bbb1(drop=_name_); by  or col0 part ordb colyn; id arm; var nn; run;


/*proc sort data=cmpn; by or col0 part ordb colyn; run;*/
/*proc transpose data=cmpn out=cmpn1(drop=_name_); by  or col0 part ordb colyn; id arm; var nn; run;*/

data compl;
set aaa1 bbb1 ;
/*set cmpn1;*/
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
/*
proc sql; 
create table compl as 
select count(subjid) as overall, "Subjects Who Completed the Study [n(%)]" as col0 length 100, 4 as or, 1 as ordb, "Yes" as colyn length 200
   from adslb where complfl="Y"
outer union corr
select count(subjid) as overall, "Subjects Who Completed the Study [n(%)]" as col0 length 100, 4 as or, 2 as ordb, "No" as colyn length 200
   from adslb where complfl="N";
*/
data adslb; set adslb; run;

proc sql; 
create table ncmpn as
select distinct count(subjid) as nn, "A"||strip(armcda) as arm, "Part A" as part length 10, 
   "Subjects Who Completed Part A [n(%)]" as col0 length 100,"  If No, Reason for Early Withdrawal from Part A [n(%)]" as col00 length 100,
   4.2 as or, 2 as ordb, status as colyn length 200
/*   from adslb where complfl="N" and armcda ne " " group by armcda,status*/
   from adslb where arma = " " and armcda ne " " and status ne "COMPLETED" 
/*and trt01a=" " and trt02a=" " and trt03a=" "*/
/*and REASEXCL ne " " */
group by armcda,status
   
outer union corr 
select distinct count(subjid) as nn, "B"||strip(armcdb) as arm, "Part B" as part length 10,
   "Subjects Who Completed Part B [n(%)]" as col0 length 100,"  If No, Reason for Early Withdrawal from Part B [n(%)]" as col00 length 100,
   4.4 as or, 2 as ordb, status as colyn length 200
   from adslb where complfl="N" and armcdb ne " " 
/*and trt04a=" " and trt05a=" " and trt06a=" "*/
/*   from adslb where armb ne " " and armcdb ne " " */
/*and REASEXCL ne " " */
group by armcdb,status;
quit;



proc sort data=ncmpn; by or col0 col00 part ordb colyn; run;
proc transpose data=ncmpn out=ncmpn1(drop=_name_); by  or col0 col00 part ordb colyn; id arm; var nn; run;

%if &numm=1 %then %do;
data compln;
set ncmpn1;
AABC=0;
ABCA=0;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;
%if &numm=2 %then %do;
data compln;
set ncmpn1;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;
%if &numm=3 %then %do;
data compln;
set ncmpn1;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;
%if &numm=4 %then %do;
data compln;
set ncmpn1;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;
%if &numm=5 %then %do;
data compln;
set ncmpn1;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;
%if &numm=6 %then %do;
data compln;
set ncmpn1;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;

%if &numm=7 %then %do;
data compln;
set ncmpn1;
*Set zero as no one refllected (where complfl="N") in category for Completer population;
AABC=0; ABCA=0; ACAB=0; BABC=0; BBCA=0; BCAB=0;
overall=sum(aabc,abca,acab,babc,bbca,bcab);
run;
%end;

/*
create table compln as  select count(subjid) as overall, "Subjects Who Completed the Study [n(%)]" as col0 length 100, 
   "  If No, Reason for Early Withdrawal [n(%)]" as col00 length 100, 4.1 as or, status as colyn length 200
   from adslb where complfl="N" group by status;
quit;
*/

*Subjects who Included;
data adslb; set adslb; run;
proc sql; 
create table inclr as 
select distinct count(subjid) as nn, "Subjects Included in Randomized Population (Part A) [n(%)]" as col0 length 100, 5 as or, "A"||armcda as arm from adslb 
   where randafl="Y" and armcda ne " " group by armcda
outer union corr
select distinct count(subjid) as nn, "Subjects Included in Randomized Population (Part B) [n(%)]" as col0 length 100, 6 as or, "B"||armcdb as arm from adslb 
   where randbfl="Y" and armcdb ne " " group by armcdb;
quit;

proc sort data=inclr; by or col0; run;
proc transpose data=inclr out=inclr1(drop=_name_); by  or col0; id arm; var nn; run;

*Add a logic to populate Safety, Pharma..., and Completer Population in each Sequence;
 
%macro sep_pop(ind,colname,m,popflag);
proc sql; 
create table &ind as 
select distinct count(subjid) as nn, "&colname [n(%)]" as col0 length 100, &m as or, "A"||armcda as arm from adslb 
   where armcda ne " " and &popflag group by armcda
outer union corr
select distinct count(subjid) as nn, "&colname [n(%)]" as col0 length 100, &m as or, "B"||armcdb as arm from adslb 
   where armcdb ne " " and &popflag group by armcdb;
quit;

proc sort data=&ind; by or col0; run;
proc transpose data=&ind out=&ind.1(drop=_name_); by  or col0; id arm; var nn; run;
%mend;

%sep_pop(_incls,%str(Subjects Included in Safety Population),7,%str(saffl="Y"));
%sep_pop(_inclpk,%str(Subjects Included in Pharmacodynamic Population),8,%str(pdfl="Y"));
%sep_pop(_inclpd,%str(Subjects Included in Pharmacokinetic Population),9,%str(pkfl="Y"));
%sep_pop(_inclcomp,%str(Subjects Included in Completer Population),10,%str(COMPLFL="Y"));


proc sql;
create table incls as select distinct count(subjid) as overall, "Subjects Included in Safety Population [n(%)]" as col0 length 100, 7 as or from adslb where saffl="Y" order by or; 
create table inclpk as select distinct count(subjid) as overall, "Subjects Included in Pharmacodynamic Population [n(%)]" as col0 length 100, 8 as or from adslb where pdfl="Y" order by or;
create table inclpd as select distinct count(subjid) as overall, "Subjects Included in Pharmacokinetic Population [n(%)]" as col0 length 100, 9 as or from adslb where pkfl="Y" order by or;
create table inclcomp as select distinct count(subjid) as overall, "Subjects Included in Completer Population [n(%)]" as col0 length 100, 10 as or from adslb where COMPLFL="Y" order by or;
quit;

data incls; merge incls _incls1; by or; run;
data inclpk; merge inclpk _inclpk1; by or; run;
data inclpd; merge inclpd _inclpd1; by or; run;
data inclcomp; merge inclcomp _inclcomp1; by or; run;

%if &numm=1 %then %do;
data inclpk; set inclpk; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
data inclpd; set inclpd; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
%end;

%if &numm=2 %then %do;
data inclpk; set inclpk; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
data inclpd; set inclpd; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
%end;

%if &numm=4 %then %do;
data inclpk; set inclpk; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
data inclpd; set inclpd; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
%end;

%if &numm=5 %then %do;
data inclpk; set inclpk; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
data inclpd; set inclpd; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
%end;

%if &numm=6 %then %do;
data inclpk; set inclpk; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
data inclpd; set inclpd; if aabc+abca+acab ne overall then do; overall=aabc+abca+acab; end; run;
%end;

*Number Randomized subjects ;

proc sql;
select count(distinct subjid) into :numa from adslb where index(randafl,"Y")>0;
select count(distinct subjid) into :numb from adslb where index(randbfl,"Y")>0;
quit;

%put &numa; %put &numb;

*Number Randomized subjects in each sequence;

data adslw; length a b $4.; set adslb; if armcda ne " " then a="A"||strip(armcda); else a=" "; if armcdb ne " " then  b="B"||strip(armcdb); else b=" "; run; 


proc sql;
select count(distinct subjid) into :aabc from adslw where index(randafl,"Y")>0 and a="AABC";
select count(distinct subjid) into :abca from adslw where index(randafl,"Y")>0 and a="ABCA";
select count(distinct subjid) into :acab from adslw where index(randafl,"Y")>0 and a="ACAB";
select count(distinct subjid) into :babc from adslw where index(randbfl,"Y")>0 and b="BABC";
select count(distinct subjid) into :bbca from adslw where index(randbfl,"Y")>0 and b="BBCA";
select count(distinct subjid) into :bcab from adslw where index(randbfl,"Y")>0 and b="BCAB";

select count(distinct subjid) into :numbr from adslb where index(randbfl,"Y")>0 and trt04a ne " ";
quit;

%put &aabc; %put &abca; %put &acab; %put &babc; %put &bbca; %put &bcab; 

*Put number overall from rnd1 to obtain in all;

proc sql;
create table ovn1 as select overall as ovall, 5 as or from rnd1 order by or;
create table ovn2 as select overall as ovall, 6 as or from rnd1 order by or;
create table ovn3 as select overall as ovall, 3 as or from rnd1 order by or;
quit;

proc sort data=inclr1; by or; run;

data inclr1;
merge inclr1 ovn1 ovn2 ;
by or;
run;

proc sort data=y3; by or; run;
proc sort data=n3; by or; run;

data y3;
merge y3 ovn3 ;
by or;
run;

data n3;
merge n3 ovn3 ;
by or;
run;

data all(drop=col00);
set enr rnd1 y3 n3 compl compln inclr1 incls inclpk inclpd inclcomp;
if or in (3 5 6) then overall=sum(aabc,abca,acab,babc,bbca,bcab); 
   else overall=overall;
if col00 ne " " then col0=col00; 
   else col0=col0;
if or=3 and part="Part A" then do;
/*a=aabc/&numa*100; b=abca/&numa*100; c=acab/&numa*100; ov=overall/&numa*100;*/
a=aabc/&aabc*100; b=abca/&abca*100; c=acab/&acab*100; ov=overall/&numa*100;
end;
if or=3 and part="Part B" then do;
/*a=babc/&numb*100; b=bbca/&numb*100; c=bcab/&numb*100; ov=overall/&numb*100;*/
/*a=babc/&babc*100; b=bbca/&bbca*100; c=bcab/&bcab*100; ov=overall/&numb*100;*/
a=babc/&babc*100; b=bbca/&bbca*100; c=bcab/&bcab*100; ov=overall/ovall*100;

end;
if or=5 then do;
a=aabc/&aabc*100; b=abca/&abca*100; c=acab/&acab*100; ov=overall/&numa*100;
end;
if or=6 then do;

/*			a=babc/&babc*100; b=bbca/&bbca*100; c=bcab/&bcab*100; ov=overall/&numb*100;*/
/*			a=babc/&babc*100; b=bbca/&bbca*100; c=bcab/&bcab*100; ov=&numbr/overall*100;*/
			a=babc/&babc*100; b=bbca/&bbca*100; c=bcab/&bcab*100; ov=overall/ovall*100;
end;
if or in (4.1  4.2  4.3  4.4  4.5)  then do;
if ^missing(aabc) then a1=aabc/&aabc*100;
if ^missing(abca) then b1=abca/&abca*100;
if ^missing(acab) then c1=acab/&acab*100; 
if ^missing(babc) then a2=babc/&babc*100;
if ^missing(bbca) then b2=bbca/&bbca*100;
if ^missing(bcab) then c2=bcab/&bcab*100; 
ov=overall/&numa*100;
end;
if or in (7  8  9  10)  then do;
a1=aabc/&aabc*100; b1=abca/&abca*100; c1=acab/&acab*100; 
a2=babc/&babc*100; b2=bbca/&bbca*100; c2=bcab/&bcab*100; 
ov=overall/&numa*100; 
end;
/*format a b c ov 8.2;*/
run;

proc sort data=all out=all;
by or orda ordb;
run;

%macro addi(k,u);
if a&k ne . then do; if aabc ne . then aabcs=strip(put(aabc,best.))||" ("||strip(put(a&k,8.1))||")"; else aabcs=" "; end;
if a&u ne . then do; if babc ne . then babcs=strip(put(babc,best.))||" ("||strip(put(a&u,8.1))||")"; else babcs=" "; end;
if b&k ne . then do; if abca ne . then abcas=strip(put(abca,best.))||" ("||strip(put(b&k,8.1))||")"; else abcas=" "; end;
if b&u ne . then do; if bbca ne . then bbcas=strip(put(bbca,best.))||" ("||strip(put(b&u,8.1))||")"; else bbcas=" "; end;
if c&k ne . then do; if acab ne . then acabs=strip(put(acab,best.))||" ("||strip(put(c&k,8.1))||")"; else acabs=" "; end;
if c&u ne . then do; if bcab ne . then bcabs=strip(put(bcab,best.))||" ("||strip(put(c&u,8.1))||")"; else bcabs=" "; end;
%mend;

data fin(drop=aabc abca acab babc bbca bcab a b c a1 b1 c1 a2 b2 c2 overall ov);
set all;
length aabcs abcas acabs babcs bbcas bcabs overalls $100. bl $10.;
%addi;
%addi(1,2);

if ov ne . then do;
overalls=strip(put(overall,best.))||" ("||strip(put(ov,8.1))||")";
end;
if or=1 then do;
if overall ne . then overalls=strip(put(overall,best.)); else overalls=" ";
end;
if or in (2) then do;
/*part=" "; */
if aabc ne . then aabcs=strip(put(aabc,best.)); else aabcs=" ";
if abca ne . then abcas=strip(put(abca,best.)); else abcas=" ";
if acab ne . then acabs=strip(put(acab,best.)); else acabs=" ";

if babc ne . then babcs=strip(put(babc,best.)); else babcs=" ";
if bbca ne . then bbcas=strip(put(bbca,best.)); else bbcas=" ";
if bcab ne . then bcabs=strip(put(bcab,best.)); else bcabs=" ";
if overall ne . then overalls=strip(put(overall,best.)); else overalls=" ";
end;
bl=" ";
run;

   data fina;
   set fin;
   if or < 5 then page=1;
   else page=2;
   run;

/*%if &num=0 %then %do;*/
   data fina;
   set fin;
   if col0=" " then delete;
   colyn=tranwrd(colyn,"OTHER, SPECIFY:","OTHER");
   if or < 5 then page=1;
   else page=2;
   run;
/*%end;*/

%macro skip;
*Obtain and fix number of subjects in each part;

proc sql;
select count(distinct subjid) into :numaa from _adslb where index(randafl,"Y")>0;
select count(distinct subjid) into :numbb from _adslb where index(randbfl,"Y")>0;
quit;

%put &numaa; %put &numbb;


%if &num=1 %then %do;
   data fina;
   set fin;
   page=1;
      if or=2 then do;
         OVERALLS=" ";
         ov=input(aabcs,best.)+input(abcas,best.)+input(acabs,best.);
         OVERALLS=strip(put(ov,best.));
      end;
   if visit in ("Day 4", "Day 5", "Day 6") then delete;
   run;
%end;

%if &num=2 %then %do;
   data fina;
   set fin;
   *page=1;
      if or=2 then do;
         OVERALLS=" ";
         ov=input(babcs,best.)+input(bbcas,best.)+input(bcabs,best.);
         OVERALLS=strip(put(ov,best.));
      end;
if or=5 then do;
ov=&numaa;
ov1=&numaa/&numaa*100;
overalls=" ";
overalls=strip(put(ov,best.))||" ("||strip(put(ov1,6.1))||")";
end;
   if visit in ("Day 1", "Day 2", "Day 3") then delete;
   run;
%end;

%mend skip;

*Remove 0 (0.0);
data fina;
set fina;
if or in (4.1  4.2  4.3  4.4) then do;
if index(AABCS,"0 (0.0)") then AABCS=" ";
else AABCS=AABCS;
if index(ABCAS,"0 (0.0)") then ABCAS=" ";
else ABCAS=ABCAS;
if index(ACABS,"0 (0.0)") then ACABS=" ";
else ACABS=ACABS;
if index(BABCS,"0 (0.0)") then BABCS=" ";
else BABCS=BABCS;
if index(BBCAS,"0 (0.0)") then BBCAS=" ";
else BBCAS=BBCAS;
if index(BCABS,"0 (0.0)") then BCABS=" ";
else BCABS=BCABS;
end;
run;


proc sort data=fina out=report;
by page or orda ordb;
run;

*******************************************************************************************************
Printing using proc report
******************************************************************************************************;
title3 "Table &disname (Continued)";
%footer1(foot1=1, ds_list=&ds_list., program=&program.);

filename filetmp temp;
filename filertf "\\algopharm.com\algorithmepharmadata\Biostudies\Montreal\&prot.\SRA\Biostatistics\Work\Outputs\tables\T&disname..DISP.rtf";

%open_rtf;

%empty_ds_fix(report);
title4 "Summary of Subject Disposition";
title5 "(&title)";

footnote3 j=l "Note(s): The percentages are based on the number of randomized subjects.";

/*%if &num=0 %then %do;*/
proc report data=report nowd split='~' spacing=1 missing style(header)=[background=white  borderbottomcolor=white bordertopcolor=black  background=_undef_ ] ;
 column page or col0 orda bl visit ordb colyn ("&linebot. Part A" aabcs abcas acabs) ("&linebot. Part B" babcs bbcas bcabs) ("Overall" overalls);
 define page      / " " order order=internal noprint;
 define or        / " " order order=internal noprint;

 define col0    / " " order order=internal style(column)=[cellwidth=2.2in just=L] style(header)=[just=center borderbottomcolor=black background=_undef_ ];
 define orda      / " " order order=internal noprint;

 define bl    / " " order order=internal style(column)=[cellwidth=0.05in just=L] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 

 define visit    / " " order order=internal style(column)=[cellwidth=0.5in just=L] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 
 define ordb      / " " order order=internal noprint;

 define colyn    / " " order order=internal style(column)=[cellwidth=1.2in just=L] style(header)=[just=center borderbottomcolor=black background=_undef_ ];

 define aabcs    / "ABC~ " order order=internal style(column)=[cellwidth=0.85in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 
 define abcas    / "BCA~ " order order=internal style(column)=[cellwidth=0.85in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 
 define acabs    / "CAB~ " order order=internal style(column)=[cellwidth=0.85in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 
 define babcs    / "ABC~ " order order=internal style(column)=[cellwidth=0.85in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 
 define bbcas    / "BCA~ " order order=internal style(column)=[cellwidth=0.85in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 
 define bcabs    / "CAB~ " order order=internal style(column)=[cellwidth=0.85in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 

 define overalls    / " " order order=internal style(column)=[cellwidth=0.8in just=center] style(header)=[just=center borderbottomcolor=black background=_undef_ ]; 


 break after page   / page;

 compute before col0 / style=[cellwidth=6in just=left];
   line " ";
 endcomp;
run;


%close_rtf;
%arrange_rtf;
%mend prnt;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.1, ds_list=ADSL, popfl=%str(armcd ne " "), title=%str(All Subjects),num=0,numm=1);

%clrw;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.2, ds_list=ADSL, popfl=%str(randafl="Y"), title=%str(Randomized Population [Part A]),num=1,numm=2);

%clrw;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.3, ds_list=ADSL, popfl=%str(randbfl="Y"), title=%str(Randomized Population [Part B]),num=2,numm=3);

%clrw;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.4, ds_list=ADSL, popfl=%str(saffl="Y"), title=%str(Safety Population),num=0,numm=4);

%clrw;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.5, ds_list=ADSL, popfl=%str(pdfl="Y"), title=%str(Pharmacodynamic Population),num=0,numm=5);

%clrw;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.6, ds_list=ADSL, popfl=%str(pkfl="Y"), title=%str(Pharmacokinetic Population),num=0,numm=6);

%clrw;

%prnt(program=T14_01_01_SUB_DISP, disname=14.1.1.7, ds_list=ADSL, popfl=%str(complfl="Y"), title=%str(Completer Population),num=0,numm=7);

%clrw;
